<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <#assign base=request.contextPath/>
    <#setting  number_format="0.##"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${base}/backstage/layui/css/layui.css" media="all">
    <script src="${base}/backstage/layui/layui.js?t=1"></script>
    <script src="${base}/backstage/js/jquery-1.8.3.min.js?t=1"></script>
    <script src="${base}/backstage/js/feng.js?t=1"></script>
    <script src="${base}/backstage/js/loading.js?t=1"></script>
</head>
<body>

<br>
<form class="layui-form" action="" style="padding-left: 15px;">
    <div class="layui-form-item">
        <label class="layui-form-label">商家名称</label>
        <div class="layui-input-block">
            <input class="layui-input" lay-verify="required" name="nameOfMerchant" id="nameOfMerchant" placeholder="请输入商家名称" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">入驻费</label>
        <div class="layui-input-block">
            <input class="layui-input" lay-verify="required" name="settlementFee" id="settlementFee" placeholder="请输入入驻费" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商家联系人</label>
        <div class="layui-input-block">
            <input class="layui-input" lay-verify="required" name="merchantContact" id="merchantContact" placeholder="请输入商家联系人" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">身份证号</label>
        <div class="layui-input-block">
            <input class="layui-input" lay-verify="required" name="idNumber" id="idNumber" placeholder="请输入身份证号" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系电话</label>
        <div class="layui-input-block">
            <input class="layui-input" lay-verify="required" name="phone" id="phone" placeholder="请输入商家联系电话" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商家地址</label>
        <div class="layui-input-block">
            <input class="layui-input" lay-verify="required" name="address" id="address" placeholder="请输入商家地址" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">账户</label>
        <div class="layui-input-block">
            <input class="layui-input" lay-verify="required" name="account" id="account" placeholder="请输入账户" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input class="layui-input" lay-verify="required" name="passWord" id="passWord" placeholder="请输入密码" autocomplete="off">
        </div>
    </div>
    <br>

    <div class="layui-upload">
        <button type="button" class="layui-btn" id="test2">商家门头照</button>
        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
            预览图：
            <div class="layui-upload-list" id="demo2"></div>
        </blockquote>
    </div>
    <br>
    <div class="layui-upload-drag" id="test10" style="position: relative;left:7%">
        <div  id="uploadDemoView">
        </div>
        <i class="layui-icon"></i>
        <p>点击上传营业执照，或将文件拖拽到此处</p>
    </div>




    <div align="center">
        <button type="button" class="layui-btn " id="saveButton">保存</button>
        <button type="button" class="layui-btn" onclick="window.history.back(-1);">返回</button>
    </div>
    <br>
    <br>
</form>
<script>


    var param = "";
    var duo = "";
    layui.use(['form', 'layer', 'upload'], function () {
        var form = layui.form
            , layer = layui.layer
            , $ = layui.jquery
            , upload = layui.upload;

        //拖拽上传
        upload.render({
            elem: '#test10'
            ,url: '${base}/file/uploadFile' //改成您自己的上传接口
            , before: function (obj) {
                layer.load(); //上传loading
            }
            ,done: function(res){
                layer.closeAll('loading'); //关闭loading
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                layer.msg('上传成功');
                // layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', res.files.file);
                $("#uploadDemoView").html("")
                $('#uploadDemoView').append('<div><img src="' + res.data + '" style="width: 342px;height: 136px"></div>'); //图片链接（base64）
                $("#test10 i").remove()
                $("#test10 p").remove()
                param += res.data;
            }
        });
        //多图片上传
        upload.render({
            elem: '#test2'
            ,url: '${base}/file/uploadFile' //改成您自己的上传接口
            ,multiple: true
            ,before: function(obj){
                layer.load(); //上传loading
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img" style="width: 342px;height: 136px">')
                });
            }
            ,done: function(res){
                //上传完毕
                layer.closeAll('loading'); //关闭loading
                if(res.code>0){
                    return layer.msg('上传失败');
                }else{
                    duo += res.data+";";
                   return  layer.msg('上传成功');
                }
            }
        });


    })


    $("#saveButton").on("click", function () {

        if ($("#nameOfMerchant").val() == "") {
            layer.msg("商家名称不能为空")
            return;
        }
        if ($("#nameOfMerchant").val().length>4) {
            layer.msg("商家名称不能超过4个字")
            return;
        }
        if ($("#merchantContact").val() == "") {
            layer.msg("商家联系人不能为空")
            return;
        }
        if ($("#idNumber").val() == "") {
            layer.msg("身份证号不能为空")
            return;
        }
        if ($("#phone").val() == "") {
            layer.msg("联系电话不能为空")
            return;
        }
        if (!(/^1(3|4|5|6|7|8|9)\d{9}$/.test($("#phone").val()))) {
            layer.msg("联系电话格式不对");
            return;
        }
        if(!(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test($("#idNumber").val()))){
            layer.msg("身份证格式不对")
            return;
        }
        if ($("#address").val() == "") {
            layer.msg("商家地址不能为空")
            return;
        }
        if ($("#account").val() == "") {
            layer.msg("账户不能为空")
            return;
        }
        if ($("#passWord").val() == "") {
            layer.msg("密码不能为空")
            return;
        }
        if ($("#settlementFee").val() == "") {
            layer.msg("入驻费不能为空")
            return;
        }
        if(param==""){
            layer.msg("营业执照不能为空")
            return;
        }
        if(duo==""){
            layer.msg("商家门头照不能为空")
            return;
        }
        var formDate = {
            account: $("#account").val(),
            passWord: $("#passWord").val(),
            nameOfMerchant: $("#nameOfMerchant").val(),
            merchantContact: $("#merchantContact").val(),
            phone: $("#phone").val(),
            idNumber: $("#idNumber").val(),
            settlementFee: $("#settlementFee").val(),
            url: param,
            duo: duo,
            address: $("#address").val()
        }

        $.ajax({
            type: "POST",
            contentType: "application/json;charset=UTF-8",
            url: "${base}/user/save",
            data: JSON.stringify(formDate),
            beforeSend: function () {
                loading("数据提交中，请稍后......");
            },
            success: function (data) {
                if (data.code === 200) {
                    layer.msg(data.msg)
                    window.location.href = "${base}/user/user.html"
                } else {
                    layer.msg(data.msg)
                }
            }
        });
    })
</script>
<script>
    <#--function checkPass(){-->

    <#--        layer.confirm('是否支付完毕,确定订单信息。',function(index){-->
    <#--            // layer.closeAll(); //疯狂模式，关闭所有层-->
    <#--            // parent.layer.closeAll(); //疯狂模式，关闭所有层-->
    <#--            window.location.href="${base}/user/user.html";-->

    <#--        })-->

    <#--        return true;-->
    <#--}-->
</script>


</body>
</html>